//
//  SharePLayerView.m
//  MiBaoTu
//
//  Created by admin on 16/9/22.
//  Copyright © 2016年 com.caesartech15. All rights reserved.
//

#import "SharePLayerView.h"

@interface SharePLayerView () {
    UIScrollView            *_scrollView;
    UIView                  *lineView;
    UIButton                *cancelBt;
    UIWindow                *_selectWindow;
}

@end
@implementation SharePLayerView

- (id)initWithFrame:(CGRect)frame withType:(ShowPlayerType)type
{
    self = [super initWithFrame:frame];
    if (self) {
        self.type = type;
        [self onCreateUI];
    }
    return self;
}

- (void)onCreateUI
{
    self.backgroundColor = [UIColor whiteColor];
    self.frame = CGRectMake(0, SCREEN_HEIGHT-300*PERCEN, SCREEN_WIDTH, 300*PERCEN);
    
    //滚动
    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 220*PERCEN)];
    _scrollView.backgroundColor = [UIColor clearColor];
    [self addSubview:_scrollView];
    
    [self addSubViewForScrollViewWithType:self.type];
    
    lineView = [[UIView alloc]initWithFrame:CGRectMake(0, _scrollView.bottom, self.width, 1)];
    lineView.backgroundColor = [UIColorFromHex(0xcccccc)colorWithAlphaComponent:.35];
    [self addSubview:lineView];
    
    cancelBt = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelBt.frame = CGRectMake(0, lineView.bottom, _scrollView.width, 80*PERCEN);
    [cancelBt setTitle:@"取消" forState:UIControlStateNormal];
    [cancelBt setTitleColor:UIColorFromHex(0x333333) forState:UIControlStateNormal];
    cancelBt.titleLabel.font = [UIFont systemFontOfSize:14.f];
    [cancelBt addTarget:self action:@selector(onCancelShowShareAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:cancelBt];
    
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
}

#pragma mark - Actions
//根据类型添加控件
- (void)addSubViewForScrollViewWithType:(ShowPlayerType)type
{
    float leftWidth = (ISIPAD?0:50*PERCEN);
    float leftJU = (ISIPAD?80*PERCEN:50*PERCEN);
    float itemWidth = (ISIPAD?120*PERCEN:100*PERCEN);
    if (type == ShowPlayerType_Moer) {

        //更多
        UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(leftWidth, 32*PERCEN, itemWidth, itemWidth)];
        imgView.image = [UIImage imageNamed:@"tianjiagq_sc"];
        [_scrollView addSubview:imgView];
        
        UILabel *_nickNameLb = [[UILabel alloc]initWithFrame:CGRectMake(imgView.left, imgView.bottom+5, imgView.width, 20)];
        _nickNameLb.backgroundColor = [UIColor clearColor];
        _nickNameLb.textAlignment = NSTextAlignmentCenter;
        _nickNameLb.textColor = UIColorFromHex(0x333333);
        _nickNameLb.font = [UIFont systemFontOfSize:(WIDTH_5S ? 10.f : 12.f)];
        _nickNameLb.text = @"添加歌曲";
        [_scrollView addSubview:_nickNameLb];

        
        UIButton *addMusciBt = [UIButton buttonWithType:UIButtonTypeCustom];
        addMusciBt.frame = CGRectMake(imgView.left, 0, imgView.width, _scrollView.height);
        addMusciBt.backgroundColor = [UIColor clearColor];
        [addMusciBt addTarget:self action:@selector(onSelectItemForAction:) forControlEvents:UIControlEventTouchUpInside];
        addMusciBt.tag = 500;
        [_scrollView addSubview:addMusciBt];
        if (ISIPAD) {
            _scrollView.width = imgView.width;
        }
    }
    else  if (type == ShowPlayerType_Share) {
        
        
        UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(leftWidth, 32*PERCEN, itemWidth, itemWidth)];
        imgView.image = [UIImage imageNamed:@"fenxiang_tc"];
        [_scrollView addSubview:imgView];
        
        UILabel *_nickNameLb = [[UILabel alloc]initWithFrame:CGRectMake(imgView.left, imgView.bottom+5, imgView.width, 20)];
        _nickNameLb.backgroundColor = [UIColor clearColor];
        _nickNameLb.textAlignment = NSTextAlignmentCenter;
        _nickNameLb.textColor = UIColorFromHex(0x333333);
        _nickNameLb.font = [UIFont systemFontOfSize:(WIDTH_5S ? 10.f : 12.f)];
        _nickNameLb.text = @"分享";
        [_scrollView addSubview:_nickNameLb];
        
        
        UIButton *addMusciBt = [UIButton buttonWithType:UIButtonTypeCustom];
        addMusciBt.frame = CGRectMake(imgView.left, 0, imgView.width, _scrollView.height);
        addMusciBt.backgroundColor = [UIColor clearColor];
        [addMusciBt addTarget:self action:@selector(onSelectItemForAction:) forControlEvents:UIControlEventTouchUpInside];
        addMusciBt.tag = 502;
        [_scrollView addSubview:addMusciBt];
        if (ISIPAD) {
            _scrollView.width = imgView.width;
        }
    }
    else if (type == ShowPlayerType_MusicMoew) {
        //每个音乐更多
//        if (ISIPAD) {
//            leftWidth = (_scrollView.width-120*PERCEN*4-80*3)/2.;
//        }
        for (int i=0; i<4; i++) {
            UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake((ISIPAD?(itemWidth+leftJU)*i:leftWidth+140*PERCEN*i), 32*PERCEN, itemWidth, itemWidth)];
            [_scrollView addSubview:imgView];
            
            UILabel *_nickNameLb = [[UILabel alloc]initWithFrame:CGRectMake(imgView.left, imgView.bottom+5, imgView.width, 20)];
            _nickNameLb.backgroundColor = [UIColor clearColor];
            _nickNameLb.textAlignment = NSTextAlignmentCenter;
            _nickNameLb.textColor = UIColorFromHex(0x333333);
            _nickNameLb.font = [UIFont systemFontOfSize:(WIDTH_5S ? 10.f : 12.f)];
            [_scrollView addSubview:_nickNameLb];
            
            
            UIButton *addMusciBt = [UIButton buttonWithType:UIButtonTypeCustom];
            addMusciBt.frame = CGRectMake(imgView.left, 0, imgView.width, _scrollView.height);
            addMusciBt.backgroundColor = [UIColor clearColor];
            [addMusciBt addTarget:self action:@selector(onSelectItemForAction:) forControlEvents:UIControlEventTouchUpInside];
            [_scrollView addSubview:addMusciBt];
            if (i == 0) {
                imgView.image = [UIImage imageNamed:@"bofang_tc"];
                _nickNameLb.text = @"播放";
                addMusciBt.tag = 501;
            }
            else  if (i == 1) {
                imgView.image = [UIImage imageNamed:@"fenxiang_tc"];
                _nickNameLb.text = @"分享";
                addMusciBt.tag = 502;
            }
            else  if (i == 2) {
                imgView.image = [UIImage imageNamed:@"quxiaoshoucang_tc"];
                _nickNameLb.text = @"取消收藏";
                addMusciBt.tag = 503;
            }
            else  if (i == 3) {
                imgView.image = [UIImage imageNamed:@"yixiazai_tc"];
                _nickNameLb.text = @"已下载";
                addMusciBt.tag = 504;
            }
        }
        if (ISIPAD) {
            _scrollView.width = itemWidth*4+leftJU*3;
        }
    }
    else if (type == ShowPlayerType_MusicSingleMoew) {
//        if (ISIPAD) {
//            leftWidth = (_scrollView.width-120*PERCEN*3-80*2)/2.;
//        }
        for (int i=0; i<2; i++) {
              UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake((ISIPAD?(itemWidth+leftJU)*i:leftWidth+140*PERCEN*i), 32*PERCEN, itemWidth, itemWidth)];
            [_scrollView addSubview:imgView];
            
            UILabel *_nickNameLb = [[UILabel alloc]initWithFrame:CGRectMake(imgView.left, imgView.bottom+5, imgView.width, 20)];
            _nickNameLb.backgroundColor = [UIColor clearColor];
            _nickNameLb.textAlignment = NSTextAlignmentCenter;
            _nickNameLb.textColor = UIColorFromHex(0x333333);
            _nickNameLb.font = [UIFont systemFontOfSize:(WIDTH_5S ? 10.f : 12.f)];
            [_scrollView addSubview:_nickNameLb];
            
            
            UIButton *addMusciBt = [UIButton buttonWithType:UIButtonTypeCustom];
            addMusciBt.frame = CGRectMake(imgView.left, 0, imgView.width, _scrollView.height);
            addMusciBt.backgroundColor = [UIColor clearColor];
            [addMusciBt addTarget:self action:@selector(onSelectItemForAction:) forControlEvents:UIControlEventTouchUpInside];
            [_scrollView addSubview:addMusciBt];
            if (i == 0) {
                imgView.image = [UIImage imageNamed:@"fenxiang_tc"];
                _nickNameLb.text = @"分享";
                addMusciBt.tag = 502;
            }
            else  if (i == 1) {
                imgView.image = [UIImage imageNamed:@"quxiaoshoucang_tc"];
                _nickNameLb.text = @"取消收藏";
                addMusciBt.tag = 503;
            }
        }
        if (ISIPAD) {
            _scrollView.width = 2*itemWidth+1*leftJU;
        }
    }
    else if (type == ShowPlayerType_AddNewMusic) {
        //新建分类
//        if (ISIPAD) {
//            leftWidth = (_scrollView.width-120*PERCEN*3-80*2)/2.;
//        }
        for (int i=0; i<2; i++) {
              UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake((ISIPAD?(itemWidth+leftJU)*i:leftWidth+140*PERCEN*i), 32*PERCEN, itemWidth, itemWidth)];
            [_scrollView addSubview:imgView];
            
            UILabel *_nickNameLb = [[UILabel alloc]initWithFrame:CGRectMake(imgView.left, imgView.bottom+5, imgView.width, 20)];
            _nickNameLb.backgroundColor = [UIColor clearColor];
            _nickNameLb.textAlignment = NSTextAlignmentCenter;
            _nickNameLb.textColor = UIColorFromHex(0x333333);
            _nickNameLb.font = [UIFont systemFontOfSize:(WIDTH_5S ? 10.f : 12.f)];
            [_scrollView addSubview:_nickNameLb];
            
            
            UIButton *addMusciBt = [UIButton buttonWithType:UIButtonTypeCustom];
            addMusciBt.frame = CGRectMake(imgView.left, 0, imgView.width, _scrollView.height);
            addMusciBt.backgroundColor = [UIColor clearColor];
            [addMusciBt addTarget:self action:@selector(onSelectItemForAction:) forControlEvents:UIControlEventTouchUpInside];
            [_scrollView addSubview:addMusciBt];
            if (i == 0) {
                imgView.image = [UIImage imageNamed:@"chongmingming"];
                _nickNameLb.text = @"重命名";
                addMusciBt.tag = 505;
            }
            else  if (i == 1) {
                imgView.image = [UIImage imageNamed:@"tianjiagq_sc"];
                _nickNameLb.text = @"添加歌曲";
                addMusciBt.tag = 500;
            }
        }
        if (ISIPAD) {
            _scrollView.width = 2*itemWidth+1*leftJU;
        }
    }
    else if (type == ShowPlayerType_DownMusic) {
        //已下载
//        if (ISIPAD) {
//            leftWidth = (_scrollView.width-120*PERCEN*3-80*2)/2.;
//        }
        for (int i=0; i<2; i++) {
             UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake((ISIPAD?(itemWidth+leftJU)*i:leftWidth+140*PERCEN*i), 32*PERCEN, itemWidth, itemWidth)];
            [_scrollView addSubview:imgView];
            
            UILabel *_nickNameLb = [[UILabel alloc]initWithFrame:CGRectMake(imgView.left, imgView.bottom+5, imgView.width, 20)];
            _nickNameLb.backgroundColor = [UIColor clearColor];
            _nickNameLb.textAlignment = NSTextAlignmentCenter;
            _nickNameLb.textColor = UIColorFromHex(0x333333);
            _nickNameLb.font = [UIFont systemFontOfSize:(WIDTH_5S ? 10.f : 12.f)];
            [_scrollView addSubview:_nickNameLb];
            
            
            UIButton *addMusciBt = [UIButton buttonWithType:UIButtonTypeCustom];
            addMusciBt.frame = CGRectMake(imgView.left, 0, imgView.width, _scrollView.height);
            addMusciBt.backgroundColor = [UIColor clearColor];
            [addMusciBt addTarget:self action:@selector(onSelectItemForAction:) forControlEvents:UIControlEventTouchUpInside];
            [_scrollView addSubview:addMusciBt];
            if (i == 0) {
                imgView.image = [UIImage imageNamed:@"bofang_tc"];
                _nickNameLb.text = @"播放";
                addMusciBt.tag = 501;
            }
            else  if (i == 1) {
                imgView.image = [UIImage imageNamed:@"shanchu_yxz"];
                _nickNameLb.text = @"删除";
                addMusciBt.tag = 506;
            }
        }
        if (ISIPAD) {
            _scrollView.width = 2*itemWidth+1*leftJU;
        }
    }
    else if (type == ShowPlayerType_StroyAllList || type == ShowPlayerType_CollectionDowned || type == ShowPlayerType_CancelCollectionDowned) {
        //大家都在听
//        if (ISIPAD) {
//            leftWidth = (_scrollView.width-120*PERCEN*4-80*3)/2.;
//        }
        for (int i=0; i<4; i++) {
              UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake((ISIPAD?(itemWidth+leftJU)*i:leftWidth+140*PERCEN*i), 32*PERCEN, itemWidth, itemWidth)];
            [_scrollView addSubview:imgView];
            
            UILabel *_nickNameLb = [[UILabel alloc]initWithFrame:CGRectMake(imgView.left, imgView.bottom+5, imgView.width, 20)];
            _nickNameLb.backgroundColor = [UIColor clearColor];
            _nickNameLb.textAlignment = NSTextAlignmentCenter;
            _nickNameLb.textColor = UIColorFromHex(0x333333);
            _nickNameLb.font = [UIFont systemFontOfSize:(WIDTH_5S ? 10.f : 12.f)];
            [_scrollView addSubview:_nickNameLb];
            
            
            UIButton *addMusciBt = [UIButton buttonWithType:UIButtonTypeCustom];
            addMusciBt.frame = CGRectMake(imgView.left, 0, imgView.width, _scrollView.height);
            addMusciBt.backgroundColor = [UIColor clearColor];
            [addMusciBt addTarget:self action:@selector(onSelectItemForAction:) forControlEvents:UIControlEventTouchUpInside];
            [_scrollView addSubview:addMusciBt];
            if (i == 0) {
                imgView.image = [UIImage imageNamed:@"bofang_tc"];
                _nickNameLb.text = @"播放";
                addMusciBt.tag = 501;
            }
            else  if (i == 1) {
                imgView.image = [UIImage imageNamed:@"fenxiang_tc"];
                _nickNameLb.text = @"分享";
                addMusciBt.tag = 502;
            }
            else  if (i == 2) {
                if (type == ShowPlayerType_CancelCollectionDowned) {
                    imgView.image = [UIImage imageNamed:@"quxiaoshoucang_tc"];
                    _nickNameLb.text = @"取消收藏";
                    addMusciBt.tag = 503;
                } else {
                    imgView.image = [UIImage imageNamed:@"shoucang_tc"];
                    _nickNameLb.text = @"收藏";
                    addMusciBt.tag = 507;
                }
            }
            else  if (i == 3) {
                if (type == ShowPlayerType_CollectionDowned) {
                    imgView.image = [UIImage imageNamed:@"yixiazai_tc"];
                    _nickNameLb.text = @"已下载";
                    addMusciBt.tag = 504;
                } else {
                    imgView.image = [UIImage imageNamed:@"xiazai_tc"];
                    _nickNameLb.text = @"下载";
                    addMusciBt.tag = 504;
                }
            }
        }
        if (ISIPAD) {
            _scrollView.width = 4*itemWidth+3*leftJU;
        }
    }
    else if (type == ShowPlayerType_stroyMore) {
        //故事库-更多
//        if (ISIPAD) {
//            leftWidth = (_scrollView.width-120*PERCEN*2-80*1)/2.;
//        }
        for (int i=0; i<2; i++) {
             UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake((ISIPAD?(itemWidth+leftJU)*i:leftWidth+140*PERCEN*i), 32*PERCEN, itemWidth, itemWidth)];
            [_scrollView addSubview:imgView];
            
            UILabel *_nickNameLb = [[UILabel alloc]initWithFrame:CGRectMake(imgView.left, imgView.bottom+5, imgView.width, 20)];
            _nickNameLb.backgroundColor = [UIColor clearColor];
            _nickNameLb.textAlignment = NSTextAlignmentCenter;
            _nickNameLb.textColor = UIColorFromHex(0x333333);
            _nickNameLb.font = [UIFont systemFontOfSize:(WIDTH_5S ? 10.f : 12.f)];
            [_scrollView addSubview:_nickNameLb];
            
            
            UIButton *addMusciBt = [UIButton buttonWithType:UIButtonTypeCustom];
            addMusciBt.frame = CGRectMake(imgView.left, 0, imgView.width, _scrollView.height);
            addMusciBt.backgroundColor = [UIColor clearColor];
            [addMusciBt addTarget:self action:@selector(onSelectItemForAction:) forControlEvents:UIControlEventTouchUpInside];
            [_scrollView addSubview:addMusciBt];
            if (i == 0) {
                imgView.image = [UIImage imageNamed:@"fenxiang_tc"];
                _nickNameLb.text = @"分享";
                addMusciBt.tag = 502;
            }
            else  if (i == 1) {
                imgView.image = [UIImage imageNamed:@"shoucang_tc"];
                _nickNameLb.text = @"收藏";
                addMusciBt.tag = 507;
            }
        }
        if (ISIPAD) {
            _scrollView.width = 2*itemWidth+1*leftJU;
        }
    }
    else if (type == ShowPlayerType_stroyCellMore) {
        //故事库-cell更多
//        if (ISIPAD) {
//            leftWidth = (_scrollView.width-120*PERCEN*3-80*2)/2.;
//        }
        for (int i=0; i<3; i++) {
              UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake((ISIPAD?(itemWidth+leftJU)*i:leftWidth+140*PERCEN*i), 32*PERCEN, itemWidth, itemWidth)];
            [_scrollView addSubview:imgView];
            
            UILabel *_nickNameLb = [[UILabel alloc]initWithFrame:CGRectMake(imgView.left, imgView.bottom+5, imgView.width, 20)];
            _nickNameLb.backgroundColor = [UIColor clearColor];
            _nickNameLb.textAlignment = NSTextAlignmentCenter;
            _nickNameLb.textColor = UIColorFromHex(0x333333);
            _nickNameLb.font = [UIFont systemFontOfSize:(WIDTH_5S ? 10.f : 12.f)];
            [_scrollView addSubview:_nickNameLb];
            
            
            UIButton *addMusciBt = [UIButton buttonWithType:UIButtonTypeCustom];
            addMusciBt.frame = CGRectMake(imgView.left, 0, imgView.width, _scrollView.height);
            addMusciBt.backgroundColor = [UIColor clearColor];
            [addMusciBt addTarget:self action:@selector(onSelectItemForAction:) forControlEvents:UIControlEventTouchUpInside];
            [_scrollView addSubview:addMusciBt];
            if (i == 0) {
                imgView.image = [UIImage imageNamed:@"bofang_tc"];
                _nickNameLb.text = @"播放";
                addMusciBt.tag = 501;
            }
            else  if (i == 1) {
                imgView.image = [UIImage imageNamed:@"fenxiang_tc"];
                _nickNameLb.text = @"分享";
                addMusciBt.tag = 502;
            }
            else  if (i == 2) {
                imgView.image = [UIImage imageNamed:@"xiazai_tc"];
                _nickNameLb.text = @"下载";
                addMusciBt.tag = 504;
            }
        }
        if (ISIPAD) {
            _scrollView.width = 3*itemWidth+2*leftJU;
        }
    }
    else if (type == ShowPlayerType_stroyTabbar) {
       //故事库4个按钮 最新首发、经典儿歌、人气故事、成长必备
//        if (ISIPAD) {
//            leftWidth = (_scrollView.width-120*PERCEN*3-80*2)/2.;
//        }
        for (int i=0; i<3; i++) {
              UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake((ISIPAD?(itemWidth+leftJU)*i:leftWidth+140*PERCEN*i), 32*PERCEN, itemWidth, itemWidth)];
            [_scrollView addSubview:imgView];
            
            UILabel *_nickNameLb = [[UILabel alloc]initWithFrame:CGRectMake(imgView.left, imgView.bottom+5, imgView.width, 20)];
            _nickNameLb.backgroundColor = [UIColor clearColor];
            _nickNameLb.textAlignment = NSTextAlignmentCenter;
            _nickNameLb.textColor = UIColorFromHex(0x333333);
            _nickNameLb.font = [UIFont systemFontOfSize:(WIDTH_5S ? 10.f : 12.f)];
            [_scrollView addSubview:_nickNameLb];
            
            
            UIButton *addMusciBt = [UIButton buttonWithType:UIButtonTypeCustom];
            addMusciBt.frame = CGRectMake(imgView.left, 0, imgView.width, _scrollView.height);
            addMusciBt.backgroundColor = [UIColor clearColor];
            [addMusciBt addTarget:self action:@selector(onSelectItemForAction:) forControlEvents:UIControlEventTouchUpInside];
            [_scrollView addSubview:addMusciBt];
            if (i == 0) {
                imgView.image = [UIImage imageNamed:@"bofang_tc"];
                _nickNameLb.text = @"播放";
                addMusciBt.tag = 501;
            }
            else  if (i == 1) {
                imgView.image = [UIImage imageNamed:@"fenxiang_tc"];
                _nickNameLb.text = @"分享";
                addMusciBt.tag = 502;
            }
            else  if (i == 2) {
                imgView.image = [UIImage imageNamed:@"yixiazai_tc"];
                _nickNameLb.text = @"已下载";
                addMusciBt.tag = 504;
            }
        }
        if (ISIPAD) {
            _scrollView.width = 3*itemWidth+2*leftJU;
        }
    }
    
   
}

- (void)onSelectItemForAction:(UIButton *)bt
{
    switch (bt.tag-500) {
        case 0:
        {
            //更多-添加歌曲
            if (_delegate && [_delegate respondsToSelector:@selector(onSelctItemForMoreAddMusic:)]) {
                [_delegate onSelctItemForMoreAddMusic:self];
            }
            [self onCancelShowShareAction];
        }
            break;
        case 1:
        {
            //每个音乐更多-播放
            if (_delegate && [_delegate respondsToSelector:@selector(onSelctItemForMorePlayMusic:)]) {
                [_delegate onSelctItemForMorePlayMusic:self];
            }
            [self onCancelShowShareAction];
        }
            break;

        case 2:
        {
            //每个音乐更多-分享
            if (_delegate && [_delegate respondsToSelector:@selector(onSelctItemForMoreShareMusic:)]) {
                [_delegate onSelctItemForMoreShareMusic:self];
            }
            
            [self onCancelShowShareAction];
        }
            break;

        case 3:
        {
            //每个音乐更多-取消收藏
            if (_delegate && [_delegate respondsToSelector:@selector(onSelctItemForMoreCancelMusicCollection:)]) {
                [_delegate onSelctItemForMoreCancelMusicCollection:self];
                [self onCancelShowShareAction];
            }
        }
            break;
        case 4:
        {
            //每个音乐更多-已下载
            //查询本地是否存在这个文件，没有就可以点击进行下载；有则不了他
            if (_delegate && [_delegate respondsToSelector:@selector(onSelctItemForMoreDownMusic:)]) {
                [_delegate onSelctItemForMoreDownMusic:self];
                [self onCancelShowShareAction];
            }
        }
            break;
        case 5:
        {
            //添加歌曲-重命名
            if (_delegate && [_delegate respondsToSelector:@selector(onSelctItemForMoreChangeNewMusicName:)]) {
                [_delegate onSelctItemForMoreChangeNewMusicName:self];
                [self onCancelShowShareAction];
            }
        }
            break;
        case 6:
        {
            //已下载-删除
            if (_delegate && [_delegate respondsToSelector:@selector(onSelctItemForMoreDeleteMusic:)]) {
                [_delegate onSelctItemForMoreDeleteMusic:self];
                [self onCancelShowShareAction];
            }
        }
            break;
        case 7:
        {
            //收藏
            if (_delegate && [_delegate respondsToSelector:@selector(onSelctItemForMoreCollectionMusic:)]) {
                [_delegate onSelctItemForMoreCollectionMusic:self];
                [self onCancelShowShareAction];
            }
        }
            break;

            
        default:
            break;
    }
}

- (void)setOrientation:(UIDeviceOrientation)orientation
{
    _orientation = orientation;
}

- (void)onShowInWindow
{
    if (!_selectWindow) {
        _selectWindow = [[UIWindow alloc]initWithFrame:[UIApplication sharedApplication].keyWindow.frame];
        _selectWindow.backgroundColor = [UIColorFromHex(0x000000) colorWithAlphaComponent:.2];
        [self onTurnToOriention:_orientation];
        [_selectWindow makeKeyAndVisible];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onTapForHideSelf)];
        [_selectWindow addGestureRecognizer:tap];
    }
    [_selectWindow addSubview:self];

}

- (void)orientChange:(NSNotification *)noti {
    UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
    [self onTurnToOriention:orientation];
}

- (void)onTurnToOriention:(UIDeviceOrientation)orientation
{
    if (ISIPAD) {
        _selectWindow.transform = CGAffineTransformMakeRotation(M_PI*.5);
        _selectWindow.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH);
        self.frame = CGRectMake(0, _selectWindow.height-300*PERCEN, _selectWindow.width, 300*PERCEN);
        _scrollView.frame = CGRectMake(0, 0, _scrollView.width, 220*PERCEN);
        _scrollView.centerx = self.centerx;
        lineView.frame = CGRectMake(0, _scrollView.bottom, self.width, 1);
        cancelBt.frame = CGRectMake(0, lineView.bottom, self.width, 80*PERCEN);
    } else {
        _selectWindow.transform = CGAffineTransformMakeRotation(0);
        _selectWindow.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        self.frame = CGRectMake(0, _selectWindow.height-300*PERCEN, _selectWindow.width, 300*PERCEN);
        _scrollView.frame = CGRectMake(0, 0, _scrollView.width, 220*PERCEN);
        _scrollView.centerx = self.centerx;
        lineView.frame = CGRectMake(0, _scrollView.bottom, self.width, 1);
        cancelBt.frame = CGRectMake(0, lineView.bottom, self.width, 80*PERCEN);
    }
}

//删除
- (void)removeFromWindow
{
    [self removeFromSuperview];
    NSMutableArray *windows = [[NSMutableArray alloc]initWithArray:[UIApplication sharedApplication].windows];
    if ([windows containsObject:_selectWindow]) {
        [windows removeObject:_selectWindow];
        _selectWindow = nil;
    }
    
    [windows enumerateObjectsUsingBlock:^(UIWindow  *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (obj.windowLevel == UIWindowLevelNormal && [obj isKindOfClass:[UIWindow class]]) {
            [obj makeKeyAndVisible];
            *stop = YES;
        }
    }];
}

//取消
- (void)onCancelShowShareAction
{
    _delegate = nil;
    [self removeFromWindow];
}

- (void)onTapForHideSelf
{
    [self onCancelShowShareAction];
}

@end
